<template>
  <div class="app-container">
    <el-header>
      <el-button class="filter-item" type="primary" icon="el-icon-document-add" @click="handleCreate">
        创建
      </el-button>
    </el-header>
    <el-table
      :data="list"
      border
      style="width: 100%"
      highlight-current-row
      v-loading="loading"
      max-height="400"
    >
      <el-table-column prop="versoion" label="版本号" align="center"> </el-table-column>
      <el-table-column prop="update" label="更新时间" show-overflow-tooltip align="center" width="220" :formatter="updateTimeFormatter"></el-table-column>
      <el-table-column prop="context" label="公告内容" align="center" show-overflow-tooltip ></el-table-column>
      <el-table-column label="操作" width="200" align="center">
        <template #default="scope">
          <el-button @click="handleEeit(scope.row)" type="button" size="small">编辑</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-footer>
      <el-pagination
        :page-size=paginationDate.rows
        :total=paginationDate.total
        :current-page=paginationDate.cuurentPage
        :page-sizes=paginationDate.pageSizes
        layout='total, prev, pager, next, jumper, sizes, slot'
        @size-change='handleSizeChange'
        @current-change='handleCurrentChange'
        style="line-height: 30px; min-width:300px;"
      >
        <i @click="handReload" class="el-icon-refresh"></i>
      </el-pagination>
    </el-footer>
  </div>
</template>
<script>
import { getBbkzItem } from '@/cloudbaseapi/cloudbase-bbkz'
import { dateFormat } from '@/cloudbaseapi/cloudbase-api'
export default {
  data() {
    return {
      title: '版本控制',
      list: [],
      loading: false,
      paginationDate: {
        total: 10,
        cuurentPage: 1,
        rows: 10,
        pageSizes: [10, 20, 30, 50]
      },
      editorContent: ``
    }
  },
  async activated() {
    await this.handGetBbkzItem()
  },
  methods: {
    async handGetBbkzItem(limit = 10, page = 1) {
      this.loading = true
      const list = await getBbkzItem(limit, page)
      this.list = list.data
      this.paginationDate.total = list.total
      setTimeout(() => {
        this.loading = false
      }, 500)
    },
    handleSizeChange(val) {
      this.handGetBbkzItem(val, this.paginationDate.cuurentPage)
      this.paginationDate.rows = val
    },
    handleCurrentChange(val) {
      this.handGetBbkzItem(this.paginationDate.rows, val)
      this.paginationDate.cuurentPage = val
    },
    handReload() {
      this.getSgbItemPage(this.paginationDate.rows, this.paginationDate.cuurentPage)
    },
    updateTimeFormatter(row, column, cellValue, index) {
      return dateFormat(cellValue, 'yyyy-MM-dd hh:mm:ss')
    },
    handleEeit(row) {
      this.$router.push({
        name: 'BbkzEdit',
        query: { id: row._id }
      })
    },
    handleCreate() {
      this.$router.push('bbkzcreate')
    }
  }
}
</script>
<style scoped lang="scss">

</style>
